﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.TM
{
    public partial class SM_RoleEmployee : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
            Response.Cache.SetNoStore();
            if (!IsPostBack)
            {
                DataBindGv();

                txtRoleID.Value = Request["RoleID"].Trim();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected void DataBindGv()
        {
            string strWhere = string.Empty;
            strWhere = " 1=1 ";
            if (Autocomplete5.SelectText!= null)
                strWhere += " and name like '%" + Autocomplete5.SelectText.Trim() + "%'";
            if (txtEmployeeNo.Value.Trim() != string.Empty)
                strWhere += " and no like '%" + txtEmployeeNo.Value.Trim() + "%'";

            string strRoleID = ZLDC.BLL.t_s_tmp_allusr.GetStrEmpIDs(Request["RoleID"].Trim());
            if (strRoleID != string.Empty)
                strWhere += " and id in (" + strRoleID + ")";
            else
                strWhere += " and id=-1";
            int recount = 0;
            dlistData.DataSource = ZLDC.BLL.t_s_tmp_allusr.GetListAllUsr(strWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out recount);
            dlistData.DataBind();
            AspNetPager1.RecordCount = recount;
            ZLDC.Common.CmnFunc.setCustInfoOfAspnet(AspNetPager1);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="src"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            DataBindGv();
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            DataBindGv();
        }
        protected void dlistData_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                string empid = e.CommandArgument.ToString();
                string RoleID = Request["Roleid"].Trim();
                ZLDC.Topo.BLL.Estate.T_s_pdmBLL.DeleteT_s_Role_EmployeeByRoleIDandEmpID(RoleID, empid);
                DataBindGv();
            }
        }
        protected void dlistData_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
            if (btnDelete != null)
                btnDelete.Attributes.Add("onclick", "javascript:return confirm('确认删除该员工？');");
        }
    }
}
